import 'package:chathouse/util/base_utils.dart';
import 'package:chathouse/util/font_utils.dart';
import 'package:chathouse/widgets/form_widgets/widget_paras.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../constant/my_color.dart';

//問題類型4 輸入框(大,多行)
//問題類型13 輸入框(小,单行)
class InputWidget4And13 extends StatefulWidget {
  String? title;
  String? placeholder;
  String? text;
  int type;
  bool request;

  Function? onTextChange;
  InputWidget4And13(
      {this.title,
      this.placeholder,
      this.text,
      this.onTextChange,
      this.type = 4,
      this.request = false,
      Key? key})
      : super(key: key);

  @override
  State<InputWidget4And13> createState() => _InputWidget4And13State();
}

class _InputWidget4And13State extends State<InputWidget4And13> {
  TextEditingController controller = TextEditingController();

  @override
  void initState() {
    controller.text = widget.text ?? "";
    widget.onTextChange ?? (val) {};
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.only(left: 26.w, right: 26.w),
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Row(crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              widget.request
                  ? Text(
                      "*",
                      style: getTextStyle(18.sp, color: Colors.red),
                    )
                  : Container(),
              Expanded(
                  child: Text(
                widget.title ?? "",
                style: getTextStyle(18.sp, color: Colors.black),
              ))
            ],
          ),
          SizedBox(
            height: 12.w,
          ),
          Container(
            // height: INPUT_ITEM_HEIGHT.w,
            height: widget.type == 4 ? 112.w : INPUT_ITEM_HEIGHT.w,
            padding: EdgeInsets.symmetric(horizontal: 12.w),
            decoration: BoxDecoration(
              borderRadius: widget.type == 4
                  ? BorderRadius.circular(10.w)
                  : BorderRadius.zero,
              border: Border.all(color: MyColors.gary_158157157, width: 1.w),
            ),
            child: TextField(
              controller: controller,
              style: getTextStyle(16.sp, color: Colors.black),
              maxLines: widget.type == 4 ? 5 : 1,
              onChanged: (val) {
                widget.onTextChange!(val);
              },
              decoration: InputDecoration(
                hintText: widget.placeholder,
                hintStyle: getTextStyle(16.sp, color: MyColors.gary_210210210),
                border: InputBorder.none,
              ),
            ),
          )
        ]));
  }
}
